<?php
/**
 * Created on 6 Sep 2011
 *
 * 
 * */
 
 /**
  * @param string, The system name of vocabulary. 
  * */
function vindexes_load_vocabulary_terms($v){
	
	$vocabulary = taxonomy_vocabulary_machine_name_load($v);
	
	if(null == $vocabulary){
		return null;
	}
	
	$terms = taxonomy_get_tree($vocabulary->vid);
	
	$itemsInfo = array(
		'type' => 'ul',
		 'attributes'=>array(
              'class' => 'TermsContent'
          ),
          'containerAttributes'=>array(
              'class' => 'TermsContainer'
          )
	);
	$items = array();
	foreach($terms as $term){
		$parents = $term->parents;
		if('0' != $parents[0]){
			if(!array_key_exists('children', $items[$term->tid])){
				$item[$term->tid]['children'] = array();
			}
			$item[$term->tid]['children'][] = l($term->name, 'taxonomy/term/'.$term->tid);
			continue;
		}
		$items[$term->tid] = array(
		    'data' => l($term->name, 'taxonomy/term/'.$term->tid)
		);
	}
	
	$itemsInfo['terms'] = $items;
	
	return theme('item_list', $itemsInfo);
}
